function titleBlackToHtml(elem, childrenHtml) {
    const attributes = elem.allAttributes || {};

    // 构建属性字符串
    let attributesString = '';
    for (const [attr, value] of Object.entries(attributes)) {
        if (attr === 'style') {
            attributesString += `${attr}="${value} margin-bottom: 20px;" `;
        } else {
            attributesString += `${attr}="${value}" `;
        }
    }
    attributesString = attributesString.trim();

    // 如果是文本节点，直接返回文本内容
    if (elem.text) {
        return elem.text;
    }
    
    if (elem.myTagName === 'img') {
        const imgAttributes = elem.allAttributes || {};
        // 确保图片样式正确
        if (!imgAttributes.style) {
            imgAttributes.style = 'max-width:100%;height:auto;';
        }
        let imgAttributesString = '';
        for (const [attr, value] of Object.entries(imgAttributes)) {
            imgAttributesString += `${attr}="${value}" `;
        }
        return `<img ${imgAttributesString.trim()} />`;
    }

    // 处理表格元素
    if (elem.type === 'table') {
        return `<table ${attributesString}>${childrenHtml}</table>`;
    }
    if (elem.type === 'table-row') {
        return `<tr ${attributesString}>${childrenHtml}</tr>`;
    }
    if (elem.type === 'table-cell' && elem.isHeader) {
        return `<th ${attributesString}>${childrenHtml}</th>`;
    }
    if (elem.type === 'table-cell') {
        return `<td ${attributesString}>${childrenHtml}</td>`;
    }

    // 默认返回当前元素的 HTML
    console.log('Default element:', `<${elem.myTagName || 'div'} ${attributesString}>${childrenHtml}</${elem.myTagName || 'div'}>`);
    return `<${elem.myTagName || 'div'} ${attributesString}>${childrenHtml}</${elem.myTagName || 'div'}>`;
}

export const elemTableToHtmlConf = {
    type: 'table',
    elemToHtml: titleBlackToHtml,
};